<?php
class UserIdentity extends CUserIdentity
{
    private $_id, $_user;
	
    public function authenticate()
    {
		$user = Users::getInstance()->getByUsername($this->username);
		if($user===null){
            $this->errorCode=self::ERROR_USERNAME_INVALID;
		}
        else if(!Utils::verifyPassword($this->password.$user['user_salt'], $user['user_password'])){
            $this->errorCode=self::ERROR_PASSWORD_INVALID;
		}
        else
        {
            $this->_id=$user['user_id'];
            $this->setState('username', $user['user_username']);
			$this->_user=$user;
            $this->errorCode=self::ERROR_NONE;
        }
        return !$this->errorCode;
    }
 
    public function getId()
    {
        return $this->_id;
    }
	
	 public function getUser()
    {
        return $this->_user;
    }
}